import * as Cesium from 'cesium';
//导入补间动画
import gsap from 'gsap';

class LightCone {
  constructor(viewer) {
    this.viewer = viewer;
    this.init();
  }
  async init() {
    //设置动画参数
    this.params = {
      height: 700,
      degress: 0,
    };
    //设置模型的位置矩阵
    this.modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(
      //位置
      Cesium.Cartesian3.fromDegrees(113.3191, 23.109, this.params.height),
      //模型旋转情况角度
      new Cesium.HeadingPitchRoll(this.params.degress, 0, 0)
    );
    //添加模型
    this.model = this.viewer.scene.primitives.add(
      await Cesium.Model.fromGltfAsync({
        url: './model/pyramid.glb',
        //是否显示
        show: true,
        //设置模型的缩放比例
        scale: 200,
        //设置最小像素
        minimumPixelSize: 12,
        //设置最大放大比例
        maximumScale: 20000,
        //允许被点击
        allowPicking: false,
        //设置debug边框
        debugShowBoundingVolume: false,
        //设置debug线框
        debugWireframe: false,
        //颜色
        color: Cesium.Color.YELLOW.withAlpha(0.5),
        //设置颜色的混合模式 混合或者高光
        colorBlendMode: Cesium.ColorBlendMode.MIX,
        //设置模型的位置矩阵
        modelMatrix: this.modelMatrix,
      })
    );
    this.animate();
  }
  animate() {
    gsap.to(this.params, {
      height: 800,
      degress: Math.PI,
      //来回转
      yoyo: true,
      //重复 -1无限次
      repeat: -1,
      //时间过渡s
      duration: 1,
      //速率 匀划曲线
      ease: 'power1,inOut',
      //更新修改的模型矩阵
      onUpdate: () => {
        this.model.modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(
          //位置
          Cesium.Cartesian3.fromDegrees(113.3191, 23.109, this.params.height),
          //模型旋转情况角度
          new Cesium.HeadingPitchRoll(this.params.degress, 0, 0)
        );
      },
    });
  }
}
export default LightCone;
